

// 计算当前时间是否为几天前
export function compareTimestamp(timestamp) {
  const currentTime = new Date().getTime();
  const timeDiff = currentTime - timestamp;

  if (timeDiff < 60000) {  
    return '1分钟内';
  } else if (timeDiff < 3600000) {
    return Math.floor(timeDiff / 60000) + '分钟';
  } else if (timeDiff < 86400000) {
    return Math.floor(timeDiff / 3600000) + '小时';
  } else if (timeDiff < 2592000000) {
    return Math.floor(timeDiff / 86400000) + '天';
  } else if (timeDiff < 7776000000) {
    return Math.floor(timeDiff / 2592000000) + '月';
  } else {
    return null;
  }
}

// 回到首页
export function gotoHome(){
	uni.showModal({
		title:"提示",
		content:"页面有误将返回首页",
		showCancel:false,
		success: (res) => {
			if(res.confirm){
				uni.reLaunch({
					url:"/pages/index/index"
				})
			}
		}
	})
}


// 公共时间戳
export function getTimestamps(){
		// 获取当前时间戳
		const now = Date.now();

		// 计算三天前的时间戳
		const threeDaysAgo = now - (3 * 24 * 60 * 60 * 1000);

		// 计算两周前的时间戳
		const twoWeeksAgo = now - (14 * 24 * 60 * 60 * 1000);

		// 计算一个月前的时间戳
		const oneMonthAgo = new Date(new Date().setMonth(new Date().getMonth() - 1)).getTime();
		
		// const timestamps = getTimestamps();
		// console.log("当前时间戳:", timestamps.now);
		// console.log("三天前时间戳:",timestamps.threeDaysAgo);
		// console.log("两周前时间戳:",timestamps.twoWeeksAgo);
		// console.log("一个月前时间戳:",timestamps.oneMonthAgo);
		
		return {
			now,
			threeDaysAgo,
			twoWeeksAgo,
			oneMonthAgo
		};
}

